<?php
/***************************************************************************
*
*	
***************************************************************************/

	function auctionTheme_colorbox_stuff()
	{	
	
		echo '<link media="screen" type="text/css" rel="stylesheet" href="'.get_bloginfo('template_url').'/css/colorbox.css" />';
		/*echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>'; */
		echo '<script src="'.get_bloginfo('template_url').'/js/jquery.colorbox.js" type="text/javascript"></script>';
		
?>
		
		<script type="text/javascript">
		
		var $ = jQuery;
		
			$(document).ready(function(){
				
				$("a[rel='image_gal1']").colorbox();
				$("a[rel='image_gal2']").colorbox();
				
				$("#report-this-link").click( function() {
					
					if($("#report-this").css('display') == 'none')					
					$("#report-this").show('slow');
					else
					$("#report-this").hide('slow');
					
					return false;
				});
				
				
				$("#contact_seller-link").click( function() {
					
					if($("#contact-seller").css('display') == 'none')					
					$("#contact-seller").show('slow');
					else
					$("#contact-seller").hide('slow');
					
					return false;
				});
				
		});
		</script>

<?php
	}
	
	add_action('wp_head','auctionTheme_colorbox_stuff');	
	//=============================
	
	global $current_user;
	get_currentuserinfo();
	$uid = $current_user->ID;
	global $wpdb;


/*****************************************************
*
*	Post bid for reverse auction type.
*	Auction Theme since v4.3 - sitemile.com
*
******************************************************/	
	
	
	
	
	if(isset($_POST['bid_now_reverse']))
	{
		
	
		if(is_user_logged_in()):
		if(isset($_POST['control_id']))
		{
			$pid 		= base64_decode($_POST['control_id']);	
			$post 		= get_post($pid);
			$bid 		= trim($_POST['bid']);	
			$post 		= get_post($pid);
			$reverse    = get_post_meta(get_the_ID(), "reverse", true);
			$tm 		= current_time('timestamp',0);
			
		
			if($reverse == 'yes' || $reverse == '1'):
			
			$query = "select * from ".$wpdb->prefix."auction_bids where uid='$uid' AND pid='$pid'";
			$r = $wpdb->get_results($query);
			
				
				
				if(!is_numeric($bid)):
				
					$bid_posted = "0";
					$errors['numeric_bid_tp'] = __("Your bid must be numeric type. Eg: 9.99",'AuctionTheme');
				
				elseif($uid == $post->post_author):
					
					$bid_posted = "0";
					$errors['not_yours'] = __("You cannot bid your own auctions.",'AuctionTheme');
				
				elseif(count($r) > 0):
					
					$row 	= $r[0];
					$id 	= $row->id;
		
					
					$query 	= "update ".$wpdb->prefix."auction_bids set bid='$bid',date_made='$tm',uid='$uid' where id='$id'";
					$wpdb->query($query);
					$bid_posted = 1;
					
			
					add_post_meta($pid,'bid',$uid);
				
					 
				else:
			
					$query = "insert into ".$wpdb->prefix."auction_bids (bid, uid, pid, date_made) values('$bid','$uid','$pid','$tm')";
					$wpdb->query($query);
					$bid_posted = 1;
					
					
					add_post_meta($pid,'bid',$uid);
					
				endif; // endif has bid already
				
			endif; //endif yes reverse
			
			
		}
		
		
	
	
		if($bid_posted == 1):
			
			

			//---------------------
			
			wp_redirect(get_permalink(get_the_ID()) . "/?bid_posted=1"); 
			exit;
			
		
		endif; //endif bid posted
	
	else:
	
		//$pid 		= base64_decode($_POST['control_id']);	
		//wp_redirect(get_bloginfo('siteurl')."/wp-login.php");
		//$_SESSION['redirect_me_back'] = get_permalink($pid);	
		//exit;
		
		$bid_posted = "0";
		
		$reeg = get_bloginfo('siteurl')."/wp-login.php?action=register";
		$loog = get_bloginfo('siteurl')."/wp-login.php";
		
		$errors['reg_bid'] = sprintf(__("You need to <a href='%s'>register</a> or <a href='%s'>login</a> to bid.",'AuctionTheme'),$reeg, $loog);
		
	endif;
	}
	
/*****************************************************
*
*	buy now for normal auction type.
*	Auction Theme since v4.3 - sitemile.com
*
******************************************************/	

	if(isset($_POST['buy_now']))
	{
		if(!is_user_logged_in())
		{
			$bid_posted = "0";
			
		$reeg = get_bloginfo('siteurl')."/wp-login.php?action=register";
		$loog = get_bloginfo('siteurl')."/wp-login.php";
		
		$errors['reg_bid'] = sprintf(__("You need to <a href='%s'>register</a> or <a href='%s'>login</a> to bid.",'AuctionTheme'),$reeg, $loog);
		
		}
		elseif(isset($_POST['control_id']))
		{
			$pid 		= base64_decode($_POST['control_id']);	
			$post 		= get_post($pid);
			$closed    	= get_post_meta(get_the_ID(), "closed", true);
			
			if($closed == "0"):
			
			if($uid == $post->post_author):
					
				$bid_posted = "0";
				$errors['not_yours'] = __("You cannot bid your own auctions.",'AuctionTheme');
				
			else:
			
				wp_redirect(get_bloginfo('siteurl')."/?a_action=buy_now&pid=".$pid);
				exit;
			
			endif;
			endif;
			
			
		}
	}
	
	
/*****************************************************
*
*	Post bid for normal auction type.
*	Auction Theme since v4.3 - sitemile.com
*
******************************************************/	
	
	if(isset($_POST['bid_now']))
	{
		if(!is_user_logged_in())
		{
			$bid_posted = "0";
			
			$reeg = get_bloginfo('siteurl')."/wp-login.php?action=register";
			$loog = get_bloginfo('siteurl')."/wp-login.php";
			
			$errors['reg_bid'] = sprintf(__("You need to <a href='%s'>register</a> or <a href='%s'>login</a> to bid.",'AuctionTheme'),$reeg, $loog);
		
		}
		elseif(isset($_POST['control_id']))
		{
			$pid 		= base64_decode($_POST['control_id']);	
			$bid 		= trim($_POST['bid']);	
			$post 		= get_post($pid);
			$reverse    = get_post_meta(get_the_ID(), "reverse", true);
			$tm 		= current_time('timestamp',0);
			$closed    	= get_post_meta(get_the_ID(), "closed", true);
			
			global $current_user;
			get_currentuserinfo();
			$uid = $current_user->ID;
	
			$buy_now = get_post_meta(get_the_ID(),'buy_now',true);
			
			if($reverse != 'yes' && $closed == "0"):
			
				$highest_bid = auctionTheme_get_highest_bid(get_the_ID());
				$ownera = auctionTheme_get_highest_bid_owner(get_the_ID());
				
				if(!is_numeric($bid)):
				
					$bid_posted = "0";
					$errors['numeric_bid_tp'] = __("Your bid must be numeric type. Eg: 9.99",'AuctionTheme');
				
				elseif($uid == $post->post_author):
					
					$bid_posted = "0";
					$errors['not_yours'] = __("You cannot bid your own auctions.",'AuctionTheme');
					
				elseif(!empty($buy_now) && $bid >= $buy_now):
					
					$bid_posted = "0";
					$errors['big_bigger'] = __("Your bid is greater than the buy now price. Use buy now instead.",'AuctionTheme');	
					
				elseif($uid == $ownera):
					
					$bid_posted = "0";
					$errors['own_bid'] = __("Your bid is already the highest bid.",'AuctionTheme');
					
				elseif($highest_bid < $bid):
				//bid ok, lets put it in DB
					
					/**************************
					*
					*	Addition since v4.4.8.3
					*	AuctionTheme - sitemile.com
					*
					**************************/
					
					$automatic_bid_enable = get_option('AuctionTheme_automatic_bid_enable');
					
					if(0) : //$automatic_bid_enable == "yes"):
					
					
					$qq = "update ".$wpdb->prefix."auction_max_bids set reached='1' where uid='$uid' AND pid='$pid' ";
					$wpdb->query($qq);					
					
					$query = "insert into ".$wpdb->prefix."auction_max_bids (bid, uid, pid, date_made) values('$bid','$uid','$pid','$tm')";
					$wpdb->query($query);					
					
					$query = "select * from ".$wpdb->prefix."auction_max_bids where reached='0' AND pid='$pid' order by bid asc ";
					$res = $wpdb->get_results($query);
					
					$first = count($res) - 1;
					$i = 0;
					
					foreach($res as $row) {
					
					$uid 	= $row->uid;
					$tm 	= current_time('timestamp',0);
					$bid	= $row->bid;
					
					if($i == $first)
					{
						//is the highest get_costPrice_gen2
						$current_bid 	= get_post_meta($pid,'current_bid', $bid);
						$diff 			= 1; // get_costPrice_gen2($current_bid);
						//echo $diff;
						
						if(($current_bid + $diff) < $bid)
						{
							$bid = $current_bid + $diff;	
						}
						else
						{
							$wpdb->query("update ".$wpdb->prefix."auction_max_bids set reached='1' where id={$row->id}");	
						}
							
					}
					else
					{
						$wpdb->query("update ".$wpdb->prefix."auction_max_bids set reached='1' where id={$row->id}");							
					}
					
					//-------
					
					$query = "insert into ".$wpdb->prefix."auction_bids (bid, uid, pid, date_made) values('$bid','$uid','$pid','$tm')";
					$wpdb->query($query);
					$bid_posted = 1;
					
					add_post_meta($pid,'bid',$uid);
					update_post_meta($pid, 'current_bid', $bid);
					
					AuctionTheme_send_email_when_bid_item_bidder($pid, $uid, $bid);
					AuctionTheme_send_email_when_bid_item_owner($pid, $uid, $bid);
					
					//-----email to the other lower bidders-----
					
						global $wpdb;
						$s_o = "select distinct uid from ".$wpdb->prefix."auction_bids where uid!='$uid' AND pid='$pid'";
						$r_o = $wpdb->get_results($s_o);
					
						foreach($r_o as $row_o)
						{							
							AuctionTheme_send_email_when_bid_item_outbid($pid, $row_o->uid, $bid);
						}
					}
					//----------
					
					else:
					
						$query = "insert into ".$wpdb->prefix."auction_bids (bid, uid, pid, date_made) values('$bid','$uid','$pid','$tm')";
						$wpdb->query($query);
						$bid_posted = 1;
						
						add_post_meta($pid,'bid',$uid);
						update_post_meta($pid,'current_bid',$bid);
						

						AuctionTheme_send_email_when_bid_item_bidder($pid, $uid, $bid);
						AuctionTheme_send_email_when_bid_item_owner($pid, $uid, $bid);
						
						
						global $wpdb;
						$s_o = "select distinct uid from ".$wpdb->prefix."auction_bids where uid!='$uid' AND pid='$pid'";
						$r_0 = $wpdb->get_results($s_o);
					
						foreach($r_0 as $row_0)
						{							

							AuctionTheme_send_email_when_bid_item_outbid($pid, $row_0->uid, $bid);
						}
						
						
					endif;
					
					
					$prm = AuctionTheme_using_permalinks();
					if($prm == true)			
					wp_redirect(get_permalink(get_the_ID()) . "/?bid_posted=1"); 
					else
					{
						wp_redirect(get_permalink(get_the_ID()) . "&bid_posted=1"); 	
					}
					
					
					exit; 
					
					
				else:
	
					$errors['higher_bid'] = __("Your bid must be higher than the last bid.","AuctionTheme");
					$bid_posted = "0";
					
				endif; // endif has bid already
				
			endif; //endif yes reverse
			
			
		}
		
		
	}
	

	
	
	//=============================
	
	get_header();
?>

<div id="content">

<?php 

			if(function_exists('bcn_display'))
		{
		    echo '<div class="my_box3"><div class="padd10">';	
		    bcn_display();
			echo '</div></div><div class="clear10"></div>';
		}

?>	
	
	
	
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php

	$reverse    = get_post_meta(get_the_ID(), "reverse", true);
	$location   = get_post_meta(get_the_ID(), "Location", true);
	$ending     = get_post_meta(get_the_ID(), "ending", true);
	
	$views    	= get_post_meta(get_the_ID(), "views", true);
	$views 		= $views + 1;
	
	if(!AuctionTheme_is_owner_of_post())
	update_post_meta(get_the_ID(), "views", $views);

	
	$pid = get_the_ID();
	
	//$bid = get_post_meta(get_the_ID(), 'bid');
	//print_r($bid);
?>	




			<?php do_action('AuctionTheme_auction_page_before_title_div'); ?>


 			<div class="my_box3">
            <div class="padd10">
            
            	<div class="box_title auction_page_title"><h1><?php the_title() ?></h1></div>
                <div class="box_content">
				
					<div class="ad-page-image-holder">
						<img class="img_class" src="<?php echo AuctionTheme_get_first_post_image(get_the_ID(), 250, 170); ?>" alt="<?php the_title(); ?>" />
						
						<?php
				
				$arr = AuctionTheme_get_post_images(get_the_ID(), 4);

				if($arr)
				{
					
				
				echo '<ul class="image-gallery" style="padding-top:10px">';
				foreach($arr as $image)
				{
					echo '<li><a href="'.AuctionTheme_generate_thumb($image, -1,600).'" rel="image_gal1"><img 
					src="'.AuctionTheme_generate_thumb($image, 50,50).'" class="img_class" /></a></li>';
				}
				echo '</ul>';
				
				
				}
				//else { echo __('No images.') ;}
				
				?>
						
					</div>
				
                <?php
				
				$start_price = auctionTheme_get_start_price(get_the_ID());
				$current	 = auctionTheme_get_current_price(get_the_ID());
				$buy_now	 = auctionTheme_get_buy_it_now_price(get_the_ID());
				$closed 	 = get_post_meta(get_the_ID(),'closed',true);
				
				?>
                
				<div class="auction-page-details-holder">
                
                <?php if(AuctionTheme_is_owner_of_post()): ?>
                
                
                <div class="owner_act">
                	<div class="padd10">
                		
                        <?php if($closed == "1"): ?>
							
                            <?php printf(__('You are the owner of this auction. <a href="%s">Relist Auction</a>.','AuctionTheme'), get_bloginfo('siteurl').'/?a_action=relist_auction&pid='.get_the_ID()); ?>
                            
                        <?php else: ?>
                        
						<?php printf(__('You are the owner of this auction. <a href="%s">Edit auction</a>.','AuctionTheme'), get_bloginfo('siteurl').'/?a_action=edit_auction&pid='.get_the_ID()); ?>
                    
                    	<?php endif; ?>
                    
                    </div>
                </div>
                
                <?php endif; ?>
                
                <?php
				
			
				 
				if($closed == "0") :
				if($bid_posted == "0"): ?> 
		
                        <div class="bid_panel_err">
                        <div class="padd10">
                        <?php _e("Your bid has not been posted. Please correct the errors and try again.","AuctionTheme");
                                echo '<br/>';
                                foreach($errors as $err)
                                echo $err.'<br/>';
                         ?>
                        </div>
                        </div>
                
                <?php endif; ?>
                
                
                <?php if($_GET['bid_posted'] == 1): ?>
		
                        <div class="bid_panel_ok">
                        <div class="padd10">
                        <?php _e("Your bid has been posted.","AuctionTheme");
                                
                         ?>
                        </div>
                        </div>
                
                <?php endif; ?>
                
                
                
           		<?php
				
					
					$shipping = get_post_meta(get_the_ID(), 'shipping', true);
					if(is_numeric($shipping) && $shipping > 0 && !empty($shipping))
						$shp = '<b>'.auctionTheme_get_show_price($shipping).'</b><br/>';
					else $shipping = 0;
				
					if($shipping != 0):
				
				?>	
                
                <div class="bid_panel">
                <div class="padd10">
                <ul class="auction-details">
							<li>
								<h3><?php echo __("Shipping","AuctionTheme"); ?>:</h3>
								<p><?php echo $shp; ?></p>
							</li>
                </ul>
                </div>
                </div>
                <?php endif; ?>
                
                
                
                <?php
				
				$only_buy_now = get_post_meta(get_the_ID(), 'only_buy_now', true);
			
				if($only_buy_now != '1'):
				
				?>
                <!-- ######### -->
                
                <div class="bid_panel">
                <div class="padd10">
                <form method="post">
                	<ul class="auction-details">
							<li>
								<h3><?php echo __("Current Bid","AuctionTheme"); ?>:</h3>
								<p><?php echo auctionTheme_get_show_price(auctionTheme_get_current_price(get_the_ID())); ?></p>
							</li>
                            
                            <li>
								<h3>&nbsp;</h3>
								<p><input type="text" name="bid" size="10" /> 
                                <input type="hidden" name="control_id" value="<?php echo base64_encode(get_the_ID()); ?>" />
                                <input class="my-buttons" type="submit" name="bid_now" value="<?php _e("Place Bid","AuctionTheme"); ?>" /></p>
							</li>
                            
                	</ul>
                   </form>
                </div>
                </div>
                
                <?php endif; ?>
                
                <!-- ######### -->
                <?php 
				
				$buynow = get_post_meta(get_the_ID(),'buy_now',true);
				if(!empty($buynow)): 
				
				?>
				
                <div class="bid_panel">
                <div class="padd10">
                <form method="post"> <input type="hidden" name="control_id" value="<?php echo base64_encode(get_the_ID()); ?>" />
                	<ul class="auction-details">
                    <?php if($only_buy_now == '1'): ?>
                    
							<li>
								<h3><?php echo __("Quantity","AuctionTheme"); ?>:</h3>
								<p><?php echo get_post_meta(get_the_ID(), 'quant', true); ?> <?php echo __("items"); ?></p>
							</li>
                            
                   <?php endif; ?>     
                        	
                            <li>
								<h3><?php echo __("Buy It Now","AuctionTheme"); ?>:</h3>
								<p><?php echo auctionTheme_get_show_price(auctionTheme_get_buy_it_now_price(get_the_ID())); ?></p>
							</li>
                            
                            <li>
								<h3>&nbsp;</h3>
								<p><input type="submit" class="my-buttons2" name="buy_now" value="<?php _e("Buy Now!","AuctionTheme"); ?>" /></p>
							</li>
                            
                	</ul>
                </form>
                </div>
                </div>
                
                <?php endif; ?>
                
               
              <?php 
              
               else: 
				// auction closed
				?>
                
                <div class="bid_panel">
                <div class="padd10">
                
                	<?php
					
					$pid = get_the_ID();
					$winner = get_post_meta(get_the_ID(), 'winner', true);
					if(!empty($winner))
					{
						
						global $wpdb;
						$q = "select bid from ".$wpdb->prefix."auction_bids where pid='$pid' and winner='1'";
						$r = $wpdb->get_results($q);
						$r = $r[0];
						
						_e("Auction closed for price: ","AuctionTheme");
						echo auctionTheme_get_show_price($r->bid);
						
					}
					
					?>
                
                </div>
                </div>
                
                <?php endif; ?>
                <div class="clear10"></div>
                
						<ul class="auction-details">
                        
                        
                        <li>
								<img src="<?php echo get_bloginfo('template_url'); ?>/images/cal.png" width="20" height="20" /> 
								<h3><?php echo __("Auction ID","AuctionTheme"); ?>:</h3>
								<p>#<?php the_ID(); ?></p>
							</li>
                        
				         <?php
						 
						 $reserve = get_post_meta(get_the_ID(),'reserve',true);
						 
						 if(!empty($reserve)):
						 ?>    
                            <li>
								<img src="<?php echo get_bloginfo('template_url'); ?>/images/price.png" width="20" height="20" /> 
								<h3><?php echo __("Reserve","AuctionTheme"); ?>:</h3>
								<p><?php 
								
								$prc = auctionTheme_get_current_price(get_the_ID());
								if($prc >= $reserve) echo __('Reserve price met.',"AuctionTheme");
								else echo __('Reserve price not met.',"AuctionTheme");
								 ?></p>
							</li> 
                          <?php endif; ?>   
                                            
							<li>
								<img src="<?php echo get_bloginfo('template_url'); ?>/images/location.png" width="20" height="20" /> 
								<h3><?php echo __("Location","AuctionTheme"); ?>:</h3>
								<p><?php echo get_the_term_list( get_the_ID(), 'auction_location', '', ', ', '' ); ?></p>
							</li>
							
							<li>
								<img src="<?php echo get_bloginfo('template_url'); ?>/images/cal.png" width="20" height="20" /> 
								<h3><?php echo __("Posted on","AuctionTheme"); ?>:</h3>
								<p><?php the_time("jS \o\\f F Y \a\\t g:i A"); ?></p>
							</li>
							
							
							<li>
								<img src="<?php echo get_bloginfo('template_url'); ?>/images/clock.png" width="20" height="20" /> 
								<h3><?php echo __("Time Left","AuctionTheme"); ?>:</h3>
                                
                                <p class="expiration_auction_p"><?php echo ($closed == "0" ? ($ending - current_time('timestamp',0)) 
								: __("Expired/Closed","AuctionTheme")); ?></p>
                                
							<!--	<p><?php echo ($closed == "0" ? AuctionTheme_prepare_seconds_to_words($ending - current_time('timestamp',0)) 
								: __("Expired/Closed","AuctionTheme")); ?></p> -->
							</li>
                            
                            
                            <li>
								<img src="<?php echo get_bloginfo('template_url'); ?>/images/watch.png" width="20" height="20" /> 
								<h3><?php echo __("Watch List","AuctionTheme"); ?>:</h3>
								<p><div class="watch-list"><?php 
								
								if(is_user_logged_in())
				{

					$pers_arr = get_user_meta($uid, 'watch_list', true);
					
					if($pers_arr){
					if(	$pers_arr[$pid] == $pid) $isIn_watchlist = 1;
					else 	 $isIn_watchlist = 0;
					} else $isIn_watchlist = 0;
				}
				else
				{
					$my_arr = array();
					if($_SESSION['watch_list']){
					if(	$_SESSION['watch_list'][$pid] == $pid) $isIn_watchlist = 1;
					else  $isIn_watchlist = 1;	
					} else $isIn_watchlist = 0;

				}
				
				if($isIn_watchlist == 1):				
				?>
                
                <a class="rem-to-watchlist" rel="<?php the_ID(); ?>" 
                href="#"><?php _e('- watchlist','AuctionTheme'); ?></a>
                
                <?php else: ?>
                
                <a class="add-to-watchlist" rel="<?php the_ID(); ?>" 
                href="#"><?php _e('+ watchlist','AuctionTheme'); ?></a>
                <?php endif; ?>   
								
								
								</div></p>
							</li>
							
						</ul>
						
						
												
					</div>
				
				
				</div>
			</div>
			</div>	
			
			<div class="clear10"></div>
				<?php do_action('AuctionTheme_auction_page_before_description_div'); ?>
            
            
			<!-- ####################### -->
			
			<div class="my_box3">
            <div class="padd10">
            
            	<div class="box_title"><?php echo __("Description","AuctionTheme"); ?></div>
                <div class="box_content">
					<p><?php the_content(); ?></p>
				</div>
			</div>
            
            <div class="tags-placeholder">
            <div class="tg1"><img src="<?php echo get_bloginfo('template_url'); ?>/images/tag.png" width="20" height="20" /> </div>
            <div class="tg2"> 	 <?php the_tags(__('Tags', 'AuctionTheme').": ", ', ', ', '); ?></div> 
            <div class="tg3"> 	
            
            				<!-- AddThis Button BEGIN -->
							<div class="addthis_toolbox addthis_default_style addthis_24x24_style">
							<a class="addthis_button_preferred_1"></a>
							<a class="addthis_button_preferred_2"></a>
							<a class="addthis_button_preferred_3"></a>
							<a class="addthis_button_preferred_4"></a>
							<a class="addthis_button_compact"></a>
							<a class="addthis_counter addthis_bubble_style"></a>
							</div>
							<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4df68b4a2795dcd9"></script>
							<!-- AddThis Button END -->
            
            </div> 
            </div>
            
			</div>
			
			<div class="clear10"></div>
            
            	<?php do_action('AuctionTheme_auction_page_before_bids_div'); ?>
            <!-- ####################### -->
			<?php 
			
			$private_bids = get_post_meta(get_the_ID(), 'private_bids', true);
			$only_buy_now = get_post_meta(get_the_ID(), 'only_buy_now', true);
			
			if($only_buy_now != "1"):
			
			?>
			<div class="my_box3">
            <div class="padd10">
            
            	<div class="box_title"><?php echo __("Posted Bids",'AuctionTheme'); ?> <?php
				
				if($private_bids == 'yes') _e('[auction has private bids]','AuctionTheme');
				
				 ?></div>
                <div class="box_content">
				<?php
				
				
				$post = get_post(get_the_ID());
				global $wpdb;
				$pid = get_the_ID();
				
				$bids = "select * from ".$wpdb->prefix."auction_bids where pid='$pid' order by id DESC";
				$res  = $wpdb->get_results($bids);
			
				if($post->post_author == $uid) $owner = 1; else $owner = 0;
				
				if(count($res) > 0)
				{
					
					if($private_bids == 'yes') 
					{
						if ($owner == 1) $show_stuff = 1;
						else if(auctionTheme_current_user_has_bid($uid, $res)) $show_stuff = 1;
						else $show_stuff = 0;
					}
					else $show_stuff = 1;
					
					//------------
					
					if($show_stuff == 1):
					
						echo '<table width="100%">';
						echo '<thead><tr>';
							echo '<th>'.__('Username','AuctionTheme').'</th>';
							echo '<th>'.__('Bid Amount','AuctionTheme').'</th>';
							echo '<th>'.__('Date Made','AuctionTheme').'</th>';
							if ($owner == 1): 
								if($reverse == 'yes' || $reverse == '1')
								echo '<th>'.__('Choose Winner','AuctionTheme').'</th>';
							echo '<th>'.__('Messaging','AuctionTheme').'</th>';
							endif;
							
							if($closed == "1") echo '<th>'.__('Winner','AuctionTheme').'</th>';
							
						echo '</tr></thead><tbody>';
					
					endif;
					
					//-------------
					
					$using_perm = AuctionTheme_using_permalinks();
	
							if($using_perm)	$privurl_m = get_permalink(get_option('AuctionTheme_my_account_priv_mess_page_id')). "?";
							else $privurl_m = get_bloginfo('siteurl'). "/?page_id=". get_option('AuctionTheme_my_account_priv_mess_page_id'). "&";	
					
					foreach($res as $row)
					{
						
						if ($owner == 1) $show_this_around = 1;
						else
						{
							if($private_bids == 'yes') 
							{
								if($uid == $row->uid) 	$show_this_around = 1;
								else $show_this_around = 0;
							}
							else
							$show_this_around = 1;
							
						}
						
						if($show_this_around == 1):
						
						$user = get_userdata($row->uid);
						echo '<tr>';
						echo '<th>'.$user->user_login.'</th>';
						echo '<th>'.auctionTheme_get_show_price($row->bid).'</th>';
						echo '<th>'.date_i18n("d-M-Y H:i:s", $row->date_made).'</th>';
						if ($owner == 1 ) {
							//if($reverse == 'yes' || $reverse == '1')
							//echo '<th><a href="'.get_bloginfo('siteurl').'/choose-winner/'.get_the_ID().'/'.$row->id.'">'.__('Select','AuctionTheme').'</a></th>';						
						
							echo '<th><a href="'.$privurl_m.'priv_act=send&uid='.$row->uid.'&pid='.get_the_ID().'">'.__('Send Message','AuctionTheme').'</a></th>';
						}
						
						if($closed == "1") { if($row->winner == 1) echo '<th>'.__('Yes','AuctionTheme').'</th>'; else echo '<th>&nbsp;</th>'; }
						
						echo '</tr>';
						
						
						endif;
					}
					
					echo '</tbody></table>';
				}
				else _e("No bids placed yet.",'AuctionTheme');
				?>	
				</div>
			</div>
			</div>
			
			<div class="clear10"></div> <?php endif; ?>
			
			<!-- ####################### -->
				<?php do_action('AuctionTheme_auction_page_before_image_gallery_div'); ?>
			<div class="my_box3">
            <div class="padd10">
            
            	<div class="box_title"><?php echo __("Image Gallery",'AuctionTheme'); ?></div>
                <div class="box_content">
				<?php
				
				$arr = AuctionTheme_get_post_images(get_the_ID());
				
				if($arr)
				{
					
				
				echo '<ul class="image-gallery">';
				foreach($arr as $image)
				{
					echo '<li><a href="'.AuctionTheme_generate_thumb($image, -1,600).'" rel="image_gal2"><img src="'.AuctionTheme_generate_thumb($image, 100,80).'" 
					class="img_class" /></a></li>';
				}
				echo '</ul>';
				
				}
				else { echo __('No images.','AuctionTheme') ;}
				
				?>
				
				
				</div>
			</div>
			</div>
			
			<div class="clear10"></div>
			
			<!-- ####################### -->
				<?php do_action('AuctionTheme_auction_page_before_map_div'); ?>
                
                <?php
				
					$AuctionTheme_enable_locations = get_option('AuctionTheme_enable_locations');
					if($AuctionTheme_enable_locations != 'no'):
				
				?>
                
			<div class="my_box3">
            <div class="padd10">
            
            	<div class="box_title"><?php echo __("Map Location",'AuctionTheme'); ?></div>
                <div class="box_content">
	
				<div id="map" style="width: 655px; height: 300px;border:2px solid #ccc;float:left"></div>
				
                <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
            
            <script type="text/javascript"
            src="<?php echo get_bloginfo('template_url'); ?>/js/mk.js"></script> 
                                                <script type="text/javascript"> 
   
	  var geocoder;
  var map;
  function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 13,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map"), myOptions);
  }

  function codeAddress(address) {
    
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
        map.setCenter(results[0].geometry.location);
        var marker = new MarkerWithLabel({
            
            position: results[0].geometry.location,
			map: map,
       labelContent: address,
       labelAnchor: new google.maps.Point(22, 0),
       labelClass: "labels", // the CSS class for the label
       labelStyle: {opacity: 1.0}

        });
      } else {
        //alert("Geocode was not successful for the following reason: " + status);
      }
    });
  }

initialize();

codeAddress("<?php 

	global $post;
	$pid = $post->ID;

	$terms = wp_get_post_terms($pid,'auction_location');
	foreach($terms as $term)
	{
		echo $term->name.",";
	}

	$location = get_post_meta($pid, "Location", true);	
	echo $location;
	
 ?>");

    </script> 
				
				</div>
			</div>
			</div>
			
			<!-- ####################### -->
			<?php
				
				endif;
				
				function AuctionTheme_add_comments_before()
				{
					?>
                    	<div class="clear10"></div>
			
                   		<!-- ####################### -->
                    	<?php do_action('AuctionTheme_auction_page_before_comments_div'); ?>
                    	<div class="my_box3">
                    	<div class="padd10">
            
                        <div class="box_title"><?php echo __("Comments",'AuctionTheme'); ?></div>
                        <div class="box_content">
                    
                    <?php	
				}
				
				function AuctionTheme_add_comments_after()
				{
					echo '</div></div></div>';	
					do_action('AuctionTheme_auction_page_after_comments_div');
				}
				
				add_filter('sitemile_before_comments', 'AuctionTheme_add_comments_before');
				add_filter('sitemile_after_comments', 'AuctionTheme_add_comments_after');
			
			
			?>
            <?php
			
			$opt = get_option('AuctionTheme_enable_comments');
			
			if($opt == "yes")	
			 comments_template(); ?>

<?php endwhile; // end of the loop. ?>



</div>

